#!/usr/bin/python
# -*- coding: UTF-8 -*-
#生成词云
import matplotlib.pyplot as plt
from scipy.misc import imread
from wordcloud import WordCloud
# 绘制词云
def generate_cloud_word(words,imgPath,resultPath):
    print(imgPath,resultPath)

    #words 为字符串数组
    cut_text =" ".join(words)
    color_mask = imread(imgPath) # 读取背景图片
    cloud = WordCloud(
        #设置字体，不指定就会出现乱码
        font_path="E:\\font\\simhei.ttf",
        #font_path=path.join(d,'simsun.ttc'),
        #设置背景色
        background_color='white',
        #词云形状
        mask=color_mask,
        #允许最大词汇
        max_words=2000,
        #最大号字体
        max_font_size=40
    )
    word_cloud = cloud.generate(cut_text) # 产生词云

    plt.imshow(word_cloud)
    plt.axis('off')
    plt.savefig(resultPath)
    plt.show()

